Page({
  data: {
    storeVoucher: {}
  },
  onLoad: function (options) {
    this.setData({
      voucherIndex: options.voucherIndex
    })
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面
    var store_cart_list = prevPage.data.store_cart_list //取上页data里的数据也可以修改
    if (options.voucherIndex) {
      this.data.storeVoucher[options.store_id] = options.voucherIndex
    }
    this.setData({
      store_cart_list: store_cart_list,
      store_id: options.store_id,
      storeVoucher: this.data.storeVoucher
    })
  },
  chooseVoucher: function (e) {
    this.setData({
      voucherIndex: e.detail.value
    })
  },
  comfirmVoucher: function () {
    var pages = getCurrentPages();
    var curPages = pages[pages.length - 1];
    var prevPage = pages[pages.length - 2]; //上一个页面
    if (this.data.voucherIndex) {
      prevPage.data.storeVoucher[this.data.store_id] = this.data.voucherIndex;
    }
    prevPage.setData({
      voucherIndex: curPages.data.voucherIndex,
      storeVoucher: prevPage.data.storeVoucher
    })
    wx.navigateBack({
      delta: 1,
    })
  },
})